﻿Imports BUS
Imports DTO

Public Class fmTraCuuPhong
    Private pCrt As PhongCrt
    Private Sub ButtonThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonThoat.Click
        Me.Close()
    End Sub
    Private Sub LoadLoaiPhong()
        Dim lhBus As New LoaiPhongBus()
        Dim ds As List(Of LoaiPhongDto)
        ds = lhBus.LayDanhSach()
        ComboBoxLoaiPhong.DataSource = ds
        ComboBoxLoaiPhong.ValueMember = "MaLoaiPhong"    'Chuoi ten property Ma cua doi tuong LopHocDto
        ComboBoxLoaiPhong.DisplayMember = "TenLoaiPhong" 'Chuoi ten property Ten cua doi tuong LopHocDto
    End Sub
    Private Sub LoadPhong()
        Dim lhBus As New PhongBus()
        Dim ds As List(Of PhongDto)
        ds = lhBus.LayDanhSach()
        ComboBoxTenPhong.DataSource = ds
        ComboBoxTenPhong.ValueMember = "MaPhong"    'Chuoi ten property Ma cua doi tuong LopHocDto
        ComboBoxTenPhong.DisplayMember = "TenPhong" 'Chuoi ten property Ten cua doi tuong LopHocDto
    End Sub


    Private Sub fmTraCuuPhong_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            LoadLoaiPhong()
            LoadPhong()
            pCrt = New PhongCrt()
            CapNhatTieuChuanTraCuu(False)
            Dim dtPhong As New DataTable()
            dgwTraCuuPhong.DataSource = dtPhong
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub CapNhatTieuChuanTraCuu(ByVal bUpdated As Boolean)
        If (bUpdated) Then
            If (txtMaPhong.Text <> "") Then
                pCrt.MaPhong = Integer.Parse(txtMaPhong.Text)
            Else
                pCrt.MaPhong = 0
            End If
            pCrt.TenPhong = ComboBoxTenPhong.Text
            pCrt.LoaiPhong = ComboBoxLoaiPhong.SelectedIndex + 1
            

            pCrt.CheckTenPhong = chkTenPhong.Checked
            pCrt.CheckLoaiPhong = chkLoaiPhong.Checked
        Else
            If (pCrt.MaPhong <> 0) Then
                txtMaPhong.Text = pCrt.MaPhong.ToString()
            End If
            ComboBoxTenPhong.Text = pCrt.TenPhong
            ComboBoxLoaiPhong.SelectedIndex = pCrt.LoaiPhong
            pCrt.CheckTenPhong = chkTenPhong.Checked
            pCrt.CheckLoaiPhong = chkLoaiPhong.Checked
            
        End If
    End Sub
    Private Sub ButtonTraCuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTraCuu.Click
        Try
            CapNhatTieuChuanTraCuu(True)
            Dim pBus As New PhongBus()
            Dim dtPhong As DataTable
            dtPhong = pBus.TimKiem(pCrt)
            dgwTraCuuPhong.DataSource = dtPhong
        Catch ex As Exception
            MessageBox.Show(ex.Message)

        End Try
    End Sub

    Private Sub chkTenPhong_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTenPhong.CheckedChanged
        If (chkTenPhong.Checked) Then
            ComboBoxTenPhong.Enabled = True
        Else
            ComboBoxTenPhong.Enabled = False
        End If
    End Sub

    Private Sub chkLoaiPhong_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkLoaiPhong.CheckedChanged
        If (chkLoaiPhong.Checked) Then
            ComboBoxLoaiPhong.Enabled = True
        Else
            ComboBoxLoaiPhong.Enabled = False
        End If
    End Sub
End Class